#include "gtest/gtest.h"

#include <cmath>
#include "arena_jumping_ball.h"

TEST(Arena, Jumpin_ball_test)
{
  Arena_jumping_ball *arena = new Arena_jumping_ball();

  // cart should start at x=0
  ASSERT_NEAR(0.0, *(arena->get_ball_x_position_p()), 0.01);

  double t = 1.0;
  double g = 9.8;
  arena->update(t);
  ASSERT_NEAR(10-0.5*t*t*g, *(arena->get_ball_y_position_p()), 0.01);

  t = 1.113;
  arena->update(t);
  ASSERT_NEAR(10-0.5*t*t*g, *(arena->get_ball_y_position_p()), 0.01);

  // ball doesn't move in x direction during the first seconds
  ASSERT_NEAR(0.0, *(arena->get_ball_x_position_p()), 0.01);

  t = 2 * sqrt(2.0);
  arena->update(t);
  ASSERT_NEAR(10, *(arena->get_ball_y_position_p()), 0.02);

  // push cart with one newton for one second
  arena->push(1.0);
  t += 1.0;
  arena->update(t);
  ASSERT_NEAR(0.05, *(arena->get_position_p()), 0.001);

  // push cart with minus one newton for one second
  arena->push(-1.0);
  t += 1.0;
  arena->update(t);
  ASSERT_NEAR(0.1, *(arena->get_position_p()), 0.001);

  // cart velocity back to zero
  ASSERT_NEAR(0.0, *(arena->get_velocity_p()), 0.001);

}
